/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Frame1.java
 *
 * Created on 15/02/2011, 11:40:27 AM
 */

package df2;

import java.awt.Color;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.JFrame;
/**
 *
 * @author Lab
 */
public class Frame1 extends javax.swing.JFrame {
static int r1,g1,b1;
static int xx,yy;
private JFrame f;
/** Creates new form Frame1 */
    public Frame1() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                formMouseReleased(evt);
            }
        });
        addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
            public void mouseDragged(java.awt.event.MouseEvent evt) {
                formMouseDragged(evt);
            }
        });

        jButton1.setText("Abrir Frame2");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jMenu1.setText(" Colores Frame 1");
        jMenu1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenu1ActionPerformed(evt);
            }
        });

        jMenuItem1.setText("Colores");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setText("Guardar Status");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);
        jMenu1.add(jMenuItem3);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(295, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(245, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
       Frame2 f22=new Frame2();

try{
    FileReader fv=new FileReader("ventana2.txt");
BufferedReader bv=new  BufferedReader(fv);
String leidoxy=bv.readLine();
String xy[]=leidoxy.split(",");
f22.setLocation(Integer.parseInt(xy[0]), Integer.parseInt(xy[1]));
f22.setSize(Integer.parseInt(xy[2]), Integer.parseInt(xy[3]));
f22.setLayout(null);
jButton1.setLocation(Integer.parseInt(xy[4]), Integer.parseInt(xy[5]));
fv.close();
bv.close();

    FileReader fr=new FileReader("colorframe2.txt");
    BufferedReader bf=new BufferedReader(fr);
    String rgb=bf.readLine();
    String cadrgb []=rgb.split(",");
    int r2=Integer.valueOf(cadrgb[0]);
    int g2=Integer.valueOf(cadrgb[1]);
    int b2=Integer.valueOf(cadrgb[2]);
f22.getContentPane().setBackground(new Color(r2,g2,b2));
}catch(IOException e){e.printStackTrace();}

f22.setVisible(true);
        this.dispose();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
 Colores c=new Colores(this);
c.setVisible(true);

    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenu1ActionPerformed

    }//GEN-LAST:event_jMenu1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
try{
      BufferedWriter fv=new BufferedWriter(new FileWriter("ventana.txt"));
      fv.write(this.getLocation().x+","+this.getLocation().y+",");
      fv.write(this.getWidth()+","+this.getHeight()+",");
      fv.write(jButton1.getX()+","+jButton1.getY());
      System.out.println(jButton1.getX()+"boton"+jButton1.getY());
   fv.close();

   BufferedReader f1=new BufferedReader(new FileReader("colorinicio.txt"));
String l=f1.readLine();
String [] cad=l.split("=");

String color1[]=cad[1].split(",");
int r=Integer.valueOf(color1[0]);

String color2[]=cad[2].split(",");
int g=Integer.valueOf(color2[0]);

String color3[]=cad[3].split("]");
int b=Integer.valueOf(color3[0]);

FileWriter fw=new FileWriter("colorframe1.txt");
fw.write(r+","+g+","+b);
fw.close();
}catch(IOException e){e.printStackTrace();}

     


    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void formMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseReleased
         
    }//GEN-LAST:event_formMouseReleased

    private void formMouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseDragged
       xx=evt.getX()-60;
       yy=evt.getY()-60;
       jButton1.setLocation(xx, yy);
      
    }//GEN-LAST:event_formMouseDragged

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
Frame1 f=new Frame1();
try{
FileReader fv=new FileReader("ventana.txt");
BufferedReader bv=new  BufferedReader(fv);
String leidoxy=bv.readLine();
String xy[]=leidoxy.split(",");
f.setLocation(Integer.parseInt(xy[0]), Integer.parseInt(xy[1]));
f.setSize(Integer.parseInt(xy[2]), Integer.parseInt(xy[3]));
f.setLayout(null);
jButton1.setLocation(Integer.parseInt(xy[4]), Integer.parseInt(xy[5]));
fv.close();
bv.close();


FileReader fr=new FileReader("colorframe1.txt");
    BufferedReader bf=new BufferedReader(fr);
    String rgb=bf.readLine();
    String cadrgb []=rgb.split(",");
    r1=Integer.valueOf(cadrgb[0]);
    g1=Integer.valueOf(cadrgb[1]);
    b1=Integer.valueOf(cadrgb[2]);
f.getContentPane().setBackground(new Color(r1,g1,b1));
fr.close();
}catch(IOException ee){
ee.printStackTrace();
}
f.setVisible(true);
//        java.awt.EventQueue.invokeLater(new Runnable() {
//            public void run() {
//                new Frame1().setVisible(true);
//            }
//        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public static javax.swing.JButton jButton1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    // End of variables declaration//GEN-END:variables

}
